const express = require('express')
const userquery = express.Router();

const mysql = require('mysql') //mysql也是个插件
const db = mysql.createPool({
    host: "127.0.0.1", //数据库的IP地址
    user: "root", //登录数据库的账户
    password: "root", //登录数据库的密码
    database: "xiangmu" //指定要操作哪个数据库
});

//查询用户数据


//查询所有用户
userquery.get('/getuserall', (req, res) => {
    var sql = "select * from user"
    db.query(sql, (err, result) => {
        console.log(result)
            // res.send(result)
    });
})


//通过电话和密码查找指定的用户 //在用户登录的时候也能使用
// 查询不到的结果为undefined
userquery.get('/getuserTelp', (req, res) => {
    var sql = "select * from user where telephone= ? and pass= ?"
        //假设传过来的电话是req.query.tele,密码是req.query.password
    db.query(sql, [req.query.tele, req.query.password], (err, result) => {
        console.log(result)
            // res.send(result)
    });
})
module.exports = userquery